<template>
    <view>
        <view class="flex align-center justify-between">
            <view class="flex" style="flex: 1">
                <image class="size-img-ss radius-lg margin-right-sm" :src="data.company?.headimgurl" mode="widthFix" />
                <view style="flex: 1">
                    <view class="text-bold">{{ data.company?.company }}</view>
                    <view class="margin-top-xs text-grey">
                        <text class="text-sm">营业时间：{{ data?.company?.opening_stime }}:00 ~ {{ data?.company?.opening_etime }}:00</text>
                    </view>
                </view>
            </view>
            <view class="cuIcon-right text-lg text-grey"></view>
        </view>
        <view v-if="list.length > 0" class="list padding-tb-base">
            <view class="" v-for="item in list" :key="item.itemid" @click="goPage(`/pages/goods/goodsdetail?id=${item.itemid}`)">
                <image :src="item.thumb" mode="widthFix" style="width: 100%" />
                <view class="title">{{ item.title }}</view>
                <view class="flex align-center justify-between margin-top-sm">
                    <view class="text-red text-bold">
                        <text>￥</text>
                        <text class="text-lg">{{ item.price }}</text>
                    </view>
                    <view class="text-sm text-grey">已售：{{ item.sales }}</view>
                </view>
            </view>
        </view>
    </view>
</template>

<script lang="ts" setup>
import { ref } from "vue";
import { goPage } from "@/utils";
import { useMemberStore } from "@/store/module/member";
import { getProductListApi } from "@/api/goods";

interface listType {
    data: AnyObject;
}
const props = withDefaults(defineProps<listType>(), {
    data: () => ({})
});
const memberStore = useMemberStore();
const list = ref<any[]>([]);

const getList = async (goods: AnyObject) => {
    const res: AnyObject = await getProductListApi({
        page: 1,
        pagesize: 6,
        username: goods?.company?.username,
        view_username: memberStore.userInfo.username
    });

    if (res.code == 200) {
        const temp: any[] = res.data;
        if (temp.length > 6) {
            list.value = temp.filter((item: any, index: number) => {
                if (index <= 5) {
                    return item;
                }
            });
        } else {
            list.value = temp;
        }
        console.log(list.value);
    } else {
        list.value = [];
    }
};

defineExpose({
    getList
});
</script>

<style scoped lang="scss">
.list {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20rpx;

    .title {
        line-height: 50rpx;
        height: 100rpx;
        display: -webkit-box;
        word-break: break-all;
        overflow: hidden;
        white-space: pre-line;
        text-overflow: ellipsis;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
    }
}
</style>
